package com.wlhse.controller;

import com.wlhse.cache.JedisClient;
import com.wlhse.dto.CheckListItemsDto;
import com.wlhse.dto.inDto.ProblemListInDto;
import com.wlhse.entity.CheckItemPojo;
import com.wlhse.entity.CheckItemStardardPojo;
import com.wlhse.service.CheckItemService;
import com.wlhse.util.GetCurrentUserIdUtil;
import com.wlhse.util.R;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController("CheckItemController")
@RequestMapping("/api/v1")
//检查项配置
public class CheckItemController {

    @Resource
    private CheckItemService checkItemService;
    @Resource
    private JedisClient jedisClient;


    @RequestMapping(value = "/check_item/tree", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public String get1() {
        return checkItemService.getTreeDto();
    }

//    @RequestMapping(value = "/check_item/tree/all", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
//    public String get2() {
//        return checkItemService.getTreeDtoV2();
//    }

    @RequestMapping(value = "/check_item", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public String addCheckItem(@RequestBody CheckItemPojo checkItemPojo) {
        return checkItemService.addCheckItem(checkItemPojo.getCheckItemCode(), checkItemPojo.getCheckItemName());
    }

    @RequestMapping(value = "/check_item", method = RequestMethod.PUT, produces = "application/json; charset=utf-8")
    public String updateCheckItem(@RequestBody CheckItemPojo checkItemPojo) {
        return checkItemService.updateCheckItem(checkItemPojo);
    }

    @RequestMapping(value = "/check_item", method = RequestMethod.DELETE, produces = "application/json; charset=utf-8")
    public String deleteCheckItem(@RequestBody CheckItemPojo checkItemPojo) {
        return checkItemService.deleteCheckItem(checkItemPojo);
    }

    //查询content
    @RequestMapping(value = "/check_item", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public String getCheckItemContent(@RequestParam(value = "checkItemCode", required = false, defaultValue = "") String checkItemCode) {
        return checkItemService.getCheckItemContent(checkItemCode);
    }

    //新增
    @RequestMapping(value = "/check_item_standard", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public String addCheckItemStandard(@RequestBody CheckItemStardardPojo checkItemStardardPojo) {
        return checkItemService.addCheckItemStandard(checkItemStardardPojo);
    }

    //删除
    @RequestMapping(value = "/check_item_standard/{id}", method = RequestMethod.DELETE, produces = "application/json; charset=utf-8")
    public String deleteCheckItemStandard(@PathVariable("id") String id) {
        return checkItemService.deleteCheckItemStandard(id);
    }
    @ApiOperation("增加checkItem父节点 --如果是增加子节点，需要将父节点code传入")
    @RequestMapping(value = "/add_check_item", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public R add_check_item(@RequestBody CheckListItemsDto checkListItemsDto) {
        return checkItemService.add_check_item(checkListItemsDto);
    }
    //@ApiOperation("增加checkItem父节点的子节点")
//    @RequestMapping(value = "/add_check_items", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
//    public R add_check_items(@RequestBody CheckListItemsDto checkListItemsDto) {
//        return checkItemService.add_check_items(checkListItemsDto);
//    }
    @ApiOperation("修改checkItem")
    @RequestMapping(value = "/update_check_items", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public R update_check_items(@RequestBody CheckListItemsDto checkListItemsDto) {
        return checkItemService.update_check_items(checkListItemsDto);
    }
    @ApiOperation("启用|停用--传值")
    @RequestMapping(value = "/StartOrStop", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public R StartOrStop(@RequestBody CheckListItemsDto checkListItemsDto) {
        return checkItemService.StartOrStop(checkListItemsDto);
    }
    @ApiOperation("通过检查表id查询树状节点图")
    @RequestMapping(value = "/queryTree/{id}", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public R queryTree(@PathVariable Integer id) {
        return checkItemService.queryTree(id);
    }
    @ApiOperation("删除问题清单模块中的记录")
    @RequestMapping(value = "/delete_checkrecord/{id}", method = RequestMethod.DELETE, produces = "application/json; charset=utf-8")
    public R delete_checkrecord(@PathVariable Integer id) {
        return checkItemService.delete_checkrecord(id);
    }
    @ApiOperation("查询问题清单模块中hseauditsystem的code为4的记录")
    @RequestMapping(value = "/query_hseauditsystem", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public R query_hseauditsystem() {
        return checkItemService.query_hseauditsystem();
    }
    @ApiOperation("查询qhseesystem的code为4的记录并合并")
    @RequestMapping(value = "/query_qhseesystem", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public R query_qhseesystem() {
        return checkItemService.query_qhseesystem();
    }
    @ApiOperation("当前登陆人在hseauditgroupmenber为组长的GroupID")
    @RequestMapping(value = "/query_information", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public String query_information(@ModelAttribute ProblemListInDto problemListInDto,@RequestParam Integer size, @RequestParam Integer page, HttpServletRequest request) {
        String token = request.getHeader("Authorization");
        String id=jedisClient.get(token);
        return checkItemService.query_information(problemListInDto,Integer.valueOf(id),page,size);
    }

}
